/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ensisa.sunspot.actor.writer.media;

import fr.ensisa.sunspot.event.AbstractEvent;
import fr.ensisa.sunspot.event.DoubleEvent;
import fr.ensisa.sunspot.event.IEvent;
import fr.ensisa.sunspot.event.IntegerEvent;
import fr.ensisa.sunspot.event.TripleEvent;

/**
 *
 * @author michel
 */
public class ConsoleMedia implements IMedia {

    public void writeHeader(long timeStamp, IEvent event) {
        printName  (event);
        printTimeStamp  (timeStamp, event);
    }

    private void printName (IEvent event) {
        if (event == null) return;
        if (!(event instanceof AbstractEvent)) return;
        System.err.print (AbstractEvent.majorInText(event.getMajor()));
    }

    private void printTimeStamp (long timeStamp, IEvent event) {
        if (event == null) return;
        System.err.print("\t");
        if (event.getTimeStamp() == 0) {
            if (timeStamp != 0) {
                System.err.print("*");
                System.err.print(timeStamp);
                System.err.print("*");
            } else {
                System.err.print(event.getTimeStamp());
            }
        } else {
            System.err.print(event.getTimeStamp());
        }
    }

    public void writeEvent (long timeStamp, IEvent event) {
        if (event == null) return;
        System.err.print("\t");
        System.err.print (AbstractEvent.stateInText(event.getState()));
        if (event instanceof TripleEvent) print ((TripleEvent) event);
        if (event instanceof IntegerEvent) print ((IntegerEvent) event);
        if (event instanceof DoubleEvent) print ((DoubleEvent) event);
    }

    private void print (DoubleEvent event) {
        System.err.print("\t");
        System.err.print(event.getIntensity());
    }

    private void print (IntegerEvent event) {
        System.err.print("\t");
        System.err.print(event.getIntensity());
    }

    private void print (TripleEvent event) {
        System.err.print("\t");
        System.err.print(event.getX());
        System.err.print("\t");
        System.err.print(event.getY());
        System.err.print("\t");
        System.err.print(event.getZ());
    }

    public void writeTrailer(long timeStamp, IEvent iEvent) {
       System.err.println ();
     }

}
